package com.softer.wxzj.controller;

import com.github.pagehelper.PageInfo;
import com.softer.wxzj.common.aop.annotation.LogRecord;
import com.softer.wxzj.common.aop.enums.LogOperationType;
import com.softer.wxzj.common.aop.enums.LogOperationUnit;
import com.softer.wxzj.common.entity.CommonResult;
import com.softer.wxzj.common.entity.Page;
import com.softer.wxzj.entity.DicRate;
import com.softer.wxzj.entity.RateConfig;
import com.softer.wxzj.service.RateConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Gong Zhiyang
 * @date 2019/7/5
 */
@RestController
@RequestMapping("/rateConfig")
public class RateConfigController {
    @Autowired
    private RateConfigService rateConfigService;

    /**
     * 获取利率类型列表
     *
     * @return 利率类型列表
     */
    @RequestMapping("/getDicRateList")
    @LogRecord(description = "获取利率类型列表", operationUnit = LogOperationUnit.RATE_CONFIG, operationType = LogOperationType.INSERT)
    public List<DicRate> getDicRateList() {
        return rateConfigService.getDicRateList();
    }

    /**
     * 新增利率配置
     *
     * @param rateConfig 利率配置
     * @return 新增结果
     */
    @RequestMapping("/add")
    @LogRecord(description = "新增利率配置", operationUnit = LogOperationUnit.RATE_CONFIG, operationType = LogOperationType.INSERT)
    public CommonResult add(RateConfig rateConfig) {
        return rateConfigService.add(rateConfig);
    }

    /**
     * 查询利率详情
     *
     * @param id ID
     * @return 详情
     */
    @RequestMapping("/getInfo")
    @LogRecord(description = "查询利率详情", operationUnit = LogOperationUnit.RATE_CONFIG, operationType = LogOperationType.SELECT)
    public RateConfig getInfo(String id) {
        return rateConfigService.getInfo(id);
    }

    /**
     * 查询利率配置列表
     *
     * @param page       分页实体
     * @param rateConfig 查询实体
     * @param fuzzy      模糊查询字段
     * @return 列表
     */
    @RequestMapping("/getList")
    @LogRecord(description = "查询利率配置列表", operationUnit = LogOperationUnit.RATE_CONFIG, operationType = LogOperationType.SELECT)
    public PageInfo<RateConfig> getList(Page page, RateConfig rateConfig, String fuzzy) {
        return rateConfigService.getList(page, rateConfig, fuzzy);
    }

    /**
     * 修改利率配置
     *
     * @param rateConfig 利率实体
     * @return 修改结果
     */
    @RequestMapping("/update")
    @LogRecord(description = "修改利率配置", operationUnit = LogOperationUnit.RATE_CONFIG, operationType = LogOperationType.UPDATE)
    public CommonResult update(RateConfig rateConfig) {
        return rateConfigService.update(rateConfig);
    }

    /**
     * 删除利率配置
     *
     * @param id 利率配置ID
     * @return 结果
     */
    @RequestMapping("/delete")
    @LogRecord(description = "删除利率配置", operationUnit = LogOperationUnit.RATE_CONFIG, operationType = LogOperationType.DELETE)
    public CommonResult delete(String id) {
        return rateConfigService.delete(id);
    }


}
